package com.suguowen.sblog.controller;

import com.suguowen.sblog.bean.User;
import com.suguowen.sblog.common.MySpringContext;
import com.suguowen.sblog.service.DiscussionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.sql.Timestamp;
import java.util.Date;

@Controller
public class DiscussionController {

    @Autowired
    DiscussionService discussionService;

    // 发评论
    @RequestMapping("/response/{articleId}")
    public String response(@PathVariable("articleId") int articleId, HttpSession httpSession,Integer receiveId,String comment){

        // 通过Shiro拦截器，判断是否已登录

        // 发送者id
        User user = MySpringContext.getInstance().getUser(httpSession.getId());
        Integer senderId = user.getId();
        // 评论日期
        Date date = new Date();
        Timestamp createTime = new Timestamp(date.getTime());

        discussionService.createComment(articleId,createTime,senderId,receiveId,comment);

        return "redirect:/toArticle/" + articleId;
    }

}
